<?php

namespace App\Repositories\Ca;

use App\Facade\AppContext;
use App\Models\BaseModel; 
use App\Models\Ca\Promotion;
use App\Models\System\Department;
use App\Models\System\Group;
use App\Repositories\BaseRepository;
use App\Utils\Output;
use App\Utils\QueryHelper;

class PromotionRepository extends BaseRepository
{

    /**
     * 分页查询
     * @param array $params
     * @return Output
     */
    function adminPager(array $params)
    {
        extract($params);
        $query = $this->model->newQuery()->where('ca__promotion.hospital_id', '=', AppContext::hospitalId());
        if (!empty($keyword)) {
            QueryHelper::like($query, 'name', $keyword);
        }
        // $query->leftJoin('ca__diseases as disease', 'disease.id', '=', 'ca__promotion.diseases_id');
        // $query->leftJoin('ca__sources as source', 'source.id', '=', 'ca__promotion.sources_id');
        $totalQuery = clone $query;
        $total = $totalQuery->count();
        // $query->select('ca__promotion.*','disease.name as diseases_name','source.name as sources_name');
        $query->select('ca__promotion.*');
        $lis = $this->setParams($query, $params, [ 'id' => 'desc']);
        return Output::pager($lis, $total);
    }

    function getModel(): BaseModel
    {
        return new Promotion();
    }
}